package com.simplefaith.delisty.client.packet.manager;

import java.util.HashMap;

import com.simplefaith.delisty.client.packet.ClientPacket;

public class PacketManager {

	private final HashMap<Integer, PacketTypeManager> packetTypeMaps;

	public PacketTypeManager getClientPacketManager() {
		return packetTypeMaps.get(ClientPacketManager.opCode);
	}

	public PacketTypeManager getServerPacketManager() {
		return packetTypeMaps.get(ServerPacketManager.opCode);
	}

	/**
	 * get Client/Server Packet Manager
	 * */
	public PacketTypeManager getPacketTypeManager(Integer packetOpCode) {
		return packetTypeMaps.get(packetOpCode);
	}

	private static PacketManager instance;

	public static PacketManager getInstance() {
		if (instance == null)
			instance = new PacketManager();
		return instance;
	}

	public PacketManager() {
		packetTypeMaps = new HashMap<Integer, PacketTypeManager>();

		ClientPacketManager clientPacketManager = new ClientPacketManager();
		ServerPacketManager serverPacketManager = new ServerPacketManager();

		packetTypeMaps
				.put(clientPacketManager.getOpCode(), clientPacketManager);
		packetTypeMaps
				.put(serverPacketManager.getOpCode(), serverPacketManager);

	}

	public void sendClientPacket(ClientPacket clientPacket) {
		// send client packet & add to packet map
		getClientPacketManager().getPacketHandler(clientPacket.getOpCode())
				.HandlePacket(clientPacket);
	}

}
